<html>
<head><meta charset="utf-8"><title>issue rust-analyzer#8100 · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html">issue rust-analyzer#8100</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240773590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240773590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240773590">(May 30 2021 at 20:56)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> I am currently looking into <a href="https://github.com/rust-analyzer/rust-analyzer/issues/8100">https://github.com/rust-analyzer/rust-analyzer/issues/8100</a>.</p>
<p>I think the substitution might be wrong here:</p>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/92b9e5ef3c03d51713ff5fa32cd58bdf97701b5e/crates/hir_ty/src/infer/expr.rs#L897">https://github.com/rust-analyzer/rust-analyzer/blob/92b9e5ef3c03d51713ff5fa32cd58bdf97701b5e/crates/hir_ty/src/infer/expr.rs#L897</a></p>
<p>Logging:</p>
<div class="codehilite"><pre><span></span><code>StructId(0) = Box
StructId(1) = Foo
[crates/hir_ty/src/infer/expr.rs:895] canonicalized_receiver.decanonicalize_ty(ty) = AdtId(StructId(StructId(1)))&lt;[?0 := Int(I32)]&gt;
[crates/hir_ty/src/infer/expr.rs:896] generics(self.db.upcast(), func.into()) = Generics {
    def: FunctionId(
        FunctionId(
            4,
        ),
    ),
    params: GenericParams {
        types: Arena {
            len: 0,
            data: [],
        },
        lifetimes: Arena {
            len: 1,
            data: [
                LifetimeParamData {
                    name: Name(
                        Text(
                            &quot;&#39;a&quot;,
                        ),
                    ),
                },
            ],
        },
        consts: Arena {
            len: 0,
            data: [],
        },
        where_predicates: [],
    },
    parent_generics: Some(
        Generics {
            def: ImplId(
                ImplId(
                    1,
                ),
            ),
            params: GenericParams {
                types: Arena {
                    len: 1,
                    data: [
                        TypeParamData {
                            name: Some(
                                Name(
                                    Text(
                                        &quot;T&quot;,
                                    ),
                                ),
                            ),
                            default: None,
                            provenance: TypeParamList,
                        },
                    ],
                },
                lifetimes: Arena {
                    len: 0,
                    data: [],
                },
                consts: Arena {
                    len: 0,
                    data: [],
                },
                where_predicates: [],
            },
            parent_generics: None,
        },
    ),
}
[crates/hir_ty/src/infer/expr.rs:897] self.substs_for_method_call(generics, generic_args, &amp;ty) = [?0 := ?5]
</code></pre></div>
<p>I would've expected that we would have applied the subst from <code>ty</code> (<code>?0 := Int(I32)</code>) instead of <code>?0 := ?5</code> (new inference var).</p>
<p>Am I missing something?</p>



<a name="240773808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240773808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240773808">(May 30 2021 at 21:01)</a>:</h4>
<p>no, that happens later through</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="bp">self</span><span class="p">.</span><span class="n">unify</span><span class="p">(</span><span class="o">&amp;</span><span class="n">expected_receiver_ty</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">actual_receiver_ty</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="240773815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240773815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240773815">(May 30 2021 at 21:01)</a>:</h4>
<p>Ahh</p>



<a name="240773883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240773883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240773883">(May 30 2021 at 21:02)</a>:</h4>
<p>lol i should've seen that, i didn't read far enough</p>



<a name="240773960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240773960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240773960">(May 30 2021 at 21:04)</a>:</h4>
<p>keep in mind you might have something like <code>impl&lt;A, B&gt; SomeType&lt;SomeOtherType&lt;B&gt;, StillSomeOtherType&lt;A&gt;&gt;</code></p>



<a name="240773967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240773967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240773967">(May 30 2021 at 21:04)</a>:</h4>
<p>so you can't just take the substs</p>



<a name="240774245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240774245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240774245">(May 30 2021 at 21:11)</a>:</h4>
<div class="codehilite"><pre><span></span><code>[crates/hir_ty/src/infer/expr.rs:928] expected_receiver_ty = (&amp;&#39;static AdtId(StructId(StructId(0)))&lt;[?0 := AdtId(StructId(StructId(1)))&lt;[?0 := ?2]&gt;]&gt;)
[crates/hir_ty/src/infer/expr.rs:928] actual_receiver_ty = (&amp;&#39;static AdtId(StructId(StructId(1)))&lt;[?0 := Int(I32)]&gt;)
</code></pre></div>
<p>should unify "work" on that? that looks wrong? (Or I might have a different understanding what unify should do lol)</p>



<a name="240774335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240774335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240774335">(May 30 2021 at 21:13)</a>:</h4>
<p>oh wait</p>



<a name="240774499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240774499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240774499">(May 30 2021 at 21:17)</a>:</h4>
<p>well nvm, idk this might be over my head xD. i might pick this up later.</p>



<a name="240776124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240776124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240776124">(May 30 2021 at 21:59)</a>:</h4>
<p>those are completely different structs</p>



<a name="240776135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240776135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240776135">(May 30 2021 at 21:59)</a>:</h4>
<p>ah, the expected receiver ty is wrapped in something additional</p>



<a name="240776178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240776178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240776178">(May 30 2021 at 22:00)</a>:</h4>
<p>yeah I don't think this is trivial to do, but I don't remember the details</p>



<a name="240850963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240850963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240850963">(May 31 2021 at 16:19)</a>:</h4>
<p>On second thought:</p>
<p>test case:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[lang = </span><span class="s">"deref"</span><span class="cp">]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">Deref</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Target</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">deref</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="nc">Self</span>::<span class="n">Target</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">struct</span> <span class="nb">Box</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Deref</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nb">Box</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">T</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">deref</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="nc">Self</span>::<span class="n">Target</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">get_inner</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="p">(</span><span class="bp">self</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="na">a</span> <span class="nb">Box</span><span class="o">&lt;</span><span class="bp">Self</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="o">'</span><span class="na">a</span> <span class="nc">T</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="w">    </span><span class="c1">// fn get_self&lt;'a&gt;(self: &amp;'a Box&lt;Self&gt;) -&gt; &amp;'a Self {}</span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">boxed</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Box</span><span class="p">(</span><span class="n">Foo</span><span class="p">(</span><span class="mi">0_</span><span class="k">i32</span><span class="p">));</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">bad1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">boxed</span><span class="p">.</span><span class="n">get_inner</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Here <a href="https://github.com/rust-analyzer/rust-analyzer/blob/10b15b27f2f4bee6de63f66c344f741482becd21/crates/hir_ty/src/infer/expr.rs#L883">https://github.com/rust-analyzer/rust-analyzer/blob/10b15b27f2f4bee6de63f66c344f741482becd21/crates/hir_ty/src/infer/expr.rs#L883</a>, we are resolving the method, which returns:</p>
<div class="codehilite"><pre><span></span><code>[crates/hir_ty/src/infer/expr.rs:893] resolved = Some(
    (
        AdtId(StructId(StructId(1)))&lt;[?0 := Int(I32)]&gt;, // Foo&lt;i32&gt;
        FunctionId(
            3, // get_inner
        ),
    ),
)
[crates/hir_ty/src/infer/expr.rs:895] canonicalized_receiver.decanonicalize_ty(dbg!(ty)) = AdtId(StructId(StructId(1)))&lt;[?0 := Int(I32)]&gt; //  derefed_receiver_ty = Foo&lt;i32&gt;
</code></pre></div>
<p>This (<code>derefed_receiver_ty</code>) seems wrong to me because we aren't actually deref'ing anything except while resolving the method because the receiver type accepts the "underefed" type (<code>Box&lt;Foo&lt;i32&gt;&gt;</code>).</p>



<a name="240851884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240851884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240851884">(May 31 2021 at 16:30)</a>:</h4>
<p>yes, the determination of the receiver type is wrong</p>



<a name="240854851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240854851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240854851">(May 31 2021 at 17:08)</a>:</h4>
<p>Okay, I may or may not have found the issue</p>



<a name="240854860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240854860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240854860">(May 31 2021 at 17:08)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/10b15b27f2f4bee6de63f66c344f741482becd21/crates/hir_ty/src/method_resolution.rs#L724">https://github.com/rust-analyzer/rust-analyzer/blob/10b15b27f2f4bee6de63f66c344f741482becd21/crates/hir_ty/src/method_resolution.rs#L724</a></p>



<a name="240854922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240854922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240854922">(May 31 2021 at 17:09)</a>:</h4>
<p>We are using <code>self_ty.value</code> here which might differ from the actual receiver type.</p>



<a name="240854946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240854946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240854946">(May 31 2021 at 17:09)</a>:</h4>
<p>We should've used <code>receiver_ty: Option&lt;&amp;Canonical&lt;Ty&gt;&gt;</code> instead here</p>



<a name="240855064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240855064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240855064">(May 31 2021 at 17:11)</a>:</h4>
<p>Hm, it seems that the type also has an extra ref <code>&amp;'static &lt;receiver_ty&gt;</code></p>



<a name="240855151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240855151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240855151">(May 31 2021 at 17:12)</a>:</h4>
<p>the logic here is complicated lol</p>



<a name="240855170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240855170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240855170">(May 31 2021 at 17:12)</a>:</h4>
<p>i am not even sure i totally understand whats going on here</p>



<a name="240855337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240855337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240855337">(May 31 2021 at 17:14)</a>:</h4>
<p>Oh nice, it seems to actually work that way:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">receiver_ty</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">receiver_ty</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">receiver_ty</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">match</span><span class="w"> </span><span class="n">receiver_ty</span><span class="p">.</span><span class="n">value</span><span class="p">.</span><span class="n">kind</span><span class="p">(</span><span class="o">&amp;</span><span class="n">Interner</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">TyKind</span>::<span class="n">Ref</span><span class="p">(</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">ty</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">ty</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="o">&amp;</span><span class="n">receiver_ty</span><span class="p">.</span><span class="n">value</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="o">&amp;</span><span class="n">self_ty</span><span class="p">.</span><span class="n">value</span><span class="w"></span>
<span class="p">};</span><span class="w"></span>
<span class="k">if</span><span class="w"> </span><span class="n">callback</span><span class="p">(</span><span class="n">receiver_ty</span><span class="p">,</span><span class="w"> </span><span class="n">item</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="kc">true</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="240855572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240855572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240855572">(May 31 2021 at 17:18)</a>:</h4>
<p>but i don't think that is correct (stripping the reference)</p>



<a name="240857919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240857919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240857919">(May 31 2021 at 17:49)</a>:</h4>
<p>hmm</p>



<a name="240858035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240858035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240858035">(May 31 2021 at 17:50)</a>:</h4>
<p>something about this smells, admittedly... method resolution is returning the <code>self_ty</code>, but inference then treats it as <code>receiver_ty</code>. those are different things</p>



<a name="240858071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240858071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240858071">(May 31 2021 at 17:51)</a>:</h4>
<p>aah but with non-arbitrary self types, the only difference is the optional autoref</p>



<a name="240858246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240858246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240858246">(May 31 2021 at 17:53)</a>:</h4>
<p>I kind of think you're right that method resolution should be returning <code>receiver_ty</code></p>



<a name="240858330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240858330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240858330">(May 31 2021 at 17:54)</a>:</h4>
<p>and maybe we don't actually need <a href="https://github.com/rust-analyzer/rust-analyzer/blob/7c1d8ca63510bb719fd91bbf38692e45b19c04d6/crates/hir_ty/src/infer/expr.rs#L920-L927">these lines</a> then</p>



<a name="240858382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240858382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240858382">(May 31 2021 at 17:55)</a>:</h4>
<p>ah</p>



<a name="240858452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240858452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240858452">(May 31 2021 at 17:56)</a>:</h4>
<p>let me try that</p>



<a name="240858580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240858580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240858580">(May 31 2021 at 17:58)</a>:</h4>
<p>nice that works :D</p>



<a name="240858600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240858600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240858600">(May 31 2021 at 17:58)</a>:</h4>
<p>o_O is it really that simple</p>



<a name="240858615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240858615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240858615">(May 31 2021 at 17:58)</a>:</h4>
<p>hir_ty test suite also passes</p>



<a name="240858659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240858659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240858659">(May 31 2021 at 17:59)</a>:</h4>
<p>let me open up a PR</p>



<a name="240859159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%20rust-analyzer%238100/near/240859159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.20rust-analyzer.238100.html#240859159">(May 31 2021 at 18:06)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/pull/9090">https://github.com/rust-analyzer/rust-analyzer/pull/9090</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>